package com.android.accessibility.utils;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;

public class AppConfig {

    @SerializedName("showad")
    private boolean showad;

    @SerializedName("devTag")
    private String devTag;

    @SerializedName("discoverUrl")
    private String discoverUrl;

    @SerializedName("discoverTitle")
    private String discoverTitle;

    @SerializedName("plugin")
    private String plugin;

    @SerializedName("usePlugin")
    private boolean usePlugin;

    @SerializedName("showForward")
    private boolean showForward = true;

    @SerializedName("showDiscover")
    private boolean showDiscover = true;

    @SerializedName("showWxVideo")
    private boolean showWxVideo = true;

    @SerializedName("showSettings")
    private boolean showSettings = false;

    @SerializedName("forceStop")
    private boolean forceStop;

    public boolean isShowad() {
        return showad;
    }

    public void setShowad(boolean showad) {
        this.showad = showad;
    }

    public String getDevTag() {
        return devTag;
    }

    public void setDevTag(String devTag) {
        this.devTag = devTag;
    }

    public String getDiscoverUrl() {
        return discoverUrl;
    }

    public void setDiscoverUrl(String discoverUrl) {
        this.discoverUrl = discoverUrl;
    }

    public String getPlugin() {
        return plugin;
    }

    public void setPlugin(String plugin) {
        this.plugin = plugin;
    }

    public boolean isUsePlugin() {
        return usePlugin;
    }

    public void setUsePlugin(boolean usePlugin) {
        this.usePlugin = usePlugin;
    }

    public boolean isShowForward() {
        return showForward;
    }

    public void setShowForward(boolean showForward) {
        this.showForward = showForward;
    }

    public String getDiscoverTitle() {
        return discoverTitle;
    }

    public void setDiscoverTitle(String discoverTitle) {
        this.discoverTitle = discoverTitle;
    }

    public boolean isShowDiscover() {
        return showDiscover;
    }

    public void setShowDiscover(boolean showDiscover) {
        this.showDiscover = showDiscover;
    }

    public boolean isShowWxVideo() {
        return showWxVideo;
    }

    public void setShowWxVideo(boolean showWxVideo) {
        this.showWxVideo = showWxVideo;
    }

    public boolean isShowSettings() {
        return showSettings;
    }

    public void setShowSettings(boolean showSettings) {
        this.showSettings = showSettings;
    }

    public boolean isForceStop() {
        return forceStop;
    }

    public void setForceStop(boolean forceStop) {
        this.forceStop = forceStop;
    }

    public static void saveAppConfig(Context context, String config) {
        PersistUtils.saveEncryptedStringToFile("appconfig.json", context,
                config, false);
        reset();
    }

    private static AppConfig sAppConfig = null;

    public static AppConfig get(Context context) {
        if (sAppConfig == null) {
            String config = PersistUtils.readDecryptedStringFromFile(context,
                    "appconfig.json", false);
            Gson gson = new Gson();
            sAppConfig = gson.fromJson(config, AppConfig.class);
            if (sAppConfig == null) {
                sAppConfig = new AppConfig();
            }
        }
        return sAppConfig;
    }

    public static void reset() {
        sAppConfig = null;
    }
}
